package com.ineatconseil.yougo.cloudfoundry;

import java.util.Map;

import org.cloudfoundry.runtime.env.CloudEnvironment;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext;

public class CloudApplicationContextInitializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {

	public void initialize(ConfigurableApplicationContext applicationContext) {
		CloudEnvironment env = new CloudEnvironment();
		if (env.getInstanceInfo() != null) {
			for(Map<String, Object> service : env.getServices()) {
				System.out.println("---------------------------------------------");
				for(Map.Entry<String, Object> serviceEntry : service.entrySet()) {
					System.out.println("- " + serviceEntry.getKey() + " > " + serviceEntry);
				}
			}
			applicationContext.getEnvironment().setActiveProfiles("cloud");
		}
		else {
			applicationContext.getEnvironment().setActiveProfiles("default");
		}
	}

}